<?php
namespace app\admin\controller;
use app\admin\model\IndexTableModel;
use app\admin\model\JoinTableModel;
use think\Db;
use think\Request;

require_once (__DIR__.'/../../../vendor/ReidsLock.class.php');
class FavideoController extends Controller
{

    /**
     * 短视频列表
     * User:@hang
     */
    public function index(Request $request)
    {
        $IndexTableModel = New IndexTableModel();
        $param = $request->param();
        $whehe = array();
        $whehe[] = ['a.exposure_num','neq',-1];
        if (isset($param['member_id']) && !empty($param['member_id'])) {
            $whehe[] = ['b.member_id','=',$param['member_id']];
        }
        if (isset($param['me_uid']) && !empty($param['me_uid'])) {
            $whehe[] = ['b.me_uid|b.me_nick_name','like',"%{$param['me_uid']}%"];
        }
        if (isset($param['me_phone']) && !empty($param['me_phone'])) {
            $whehe[] = ['b.me_phone','like',"%{$param['me_phone']}%"];
        }
        if (isset($param['me_nick_name']) && !empty($param['me_nick_name'])) {
            $whehe[] = ['b.me_nick_name','like',"%{$param['me_nick_name']}%"];
        }
        if (isset($param['label_name']) && !empty($param['label_name'])) {
            $whehe[] = ['c.label_name','like',"%{$param['label_name']}%"];
        }
        if (isset($param['short_content']) && !empty($param['short_content'])) {
            $whehe[] = ['a.short_content','like',"%{$param['short_content']}%"];
        }
        if (isset($param['status']) && !empty($param['status'])) {
            $whehe[] = ['a.status','=',$param['status']];
        }
        if (isset($param['is_show']) && !empty($param['is_show'])) {
            $whehe[] = ['a.is_show','=',$param['is_show']];
        }
        if (isset($param['is_delete']) && !empty($param['is_delete'])) {
            $whehe[] = ['a.is_delete','=',$param['is_delete']];
        }
        if (isset($param['is_zx_word']) && !empty($param['is_zx_word'])) {
            if($param['is_zx_word'] == 1){
                $whehe[] = ['a.sort','=',-99];
            }
            if($param['is_zx_word'] == 2){
                $whehe[] = ['a.sort','neq',-99];
            }
        }
        $whehetime = '';
        if (isset($param['add_time']) && !empty($param['add_time'])) {
            $time_arr = explode(' - ', $param['add_time']);
            $start_time = strtotime($time_arr[0]);
            $end_time = strtotime($time_arr[1].'23:59:59');
            $whehetime = "a.add_time >= $start_time AND a.add_time <= $end_time";
        }
        $data = Db::table('fa_short_video')
            ->alias('a')
            ->join("fa_member b",'a.member_id = b.member_id','LEFT')
            ->join("fa_label c",'a.label_id = c.id','LEFT')
            ->join("fa_short_exposure_pool d",'a.pool_id = d.id','LEFT')
            ->where($whehe)
            ->where($whehetime)
            ->field('a.*,b.me_uid,b.me_nick_name,b.me_phone,c.label_name,d.pool_name,d.exposure_num as pool_exposure_num')
            ->order('a.add_time desc')
            ->paginate($this->admin['per_page'],false,['query'=>request()->param()]);
        $data->each(function ($v, $k)use($IndexTableModel) {
            switch($v['status']){
                case '1': $v['status_word'] = '正常';break;
                case '2': $v['status_word'] = '封禁';break;
            }
            switch($v['is_show']){
                case '1': $v['is_show_word'] = '展示';break;
                case '2': $v['is_show_word'] = '隐藏';break;
            }
            switch($v['is_delete']){
                case '1': $v['is_delete_word'] = '未删除';break;
                case '2': $v['is_delete_word'] = '已删除';break;
            }
            switch($v['is_real_address']){
                case '1': $v['is_real_address_word'] = '展示';break;
                case '2': $v['is_real_address_word'] = '隐藏';break;
            }
            switch($v['is_shop_address']){
                case '1': $v['is_shop_address_word'] = '展示';break;
                case '2': $v['is_shop_address_word'] = '隐藏';break;
            }
            $v['add_time'] = date('Y-m-d H:i',$v['add_time']);
            //查询是否存在推广
            $v['is_exposure_word'] = '未推广';
            $v['is_exposure'] = '-1';
            $v['exposure_id'] = '0';
            $exposureInfo = $IndexTableModel->getFindOrder('fa_short_video_exposure_order',"`short_video_id` = '{$v['id']}' and `push_status` < 2",'id,push_status','id desc');
            if(!empty($exposureInfo)){
                $v['is_exposure_word'] = $exposureInfo['push_status'] == 0?'未开始':'推广中';
                $v['is_exposure'] = $exposureInfo['push_status'] == 0?'0':'1';
                $v['exposure_id'] = $exposureInfo['id'];
            }
            $v['short_content_word'] = cutStr($v['short_content'],7);
            $v['is_zx_word'] = '否';
            if($v['sort'] == -99){
                $v['is_zx_word'] = '是';
            }
            return $v;
        });
        //关键词，排序等赋值
        $this->assign($request->get());
        $this->assign([
            'data'  => $data,
            'page'  => $data->render(),
            'total' => $data->total(),
        ]);
        return $this->fetch();
    }


    /**
     * 短视频推广详情
     * User:@hang
     */
    public function getexposureinfo($id)
    {
        $JoinTableModel = New JoinTableModel();
        $IndexTableModel = New IndexTableModel();
        $videoInfo = $JoinTableModel->getThreeJoinInfo('fa_short_video','fa_member','fa_label',"a.member_id = b.member_id","a.label_id = c.id","a.id = '{$id}'","a.*,b.me_uid,b.me_nick_name,b.me_phone,c.label_name","a.id asc");
        if(empty($videoInfo)){
            var_dump('短视频信息未查询到');die;
        }else{
            switch($videoInfo['status']){
                case '1': $videoInfo['status_word'] = '正常';break;
                case '2': $videoInfo['status_word'] = '封禁';break;
            }
            switch($videoInfo['is_show']){
                case '1': $videoInfo['is_show_word'] = '展示';break;
                case '2': $videoInfo['is_show_word'] = '隐藏';break;
            }
            switch($videoInfo['is_delete']){
                case '1': $videoInfo['is_delete_word'] = '未删除';break;
                case '2': $videoInfo['is_delete_word'] = '已删除';break;
            }
            $videoInfo['add_time'] = date('Y-m-d H:i:s',$videoInfo['add_time']);
        }
        //是否存在推广
        $exposureInfo = $JoinTableModel->getThreeJoinInfo("fa_short_video_exposure_order","fa_member","fa_short_video","a.member_id = b.member_id","a.short_video_id = c.id","a.short_video_id = '{$id}' and a.push_status < 2",'a.*,a.member_id as t_member_id,b.me_uid,b.me_nick_name,b.me_phone,c.*','a.member_id asc');
        if(!empty($exposureInfo)){
            switch($exposureInfo['push_status']){
                case '0': $exposureInfo['push_status_word'] = '未开始';break;
                case '1': $exposureInfo['push_status_word'] = '推广中';break;
                case '2': $exposureInfo['push_status_word'] = '已结束';break;
            }
            $exposureInfo['push_start_time'] = date('Y-m-d H:i:s',$exposureInfo['push_start_time']);
            $exposureInfo['push_end_time'] = date('Y-m-d H:i:s',$exposureInfo['push_end_time']);
            switch($exposureInfo['push_sex']){
                case '0': $exposureInfo['push_sex_word'] = '全部';break;
                case '1': $exposureInfo['push_sex_word'] = '男';break;
                case '2': $exposureInfo['push_sex_word'] = '女';break;
            }
            $exposureInfo['push_minage_word'] = '全部';
            if(!empty($exposureInfo['push_minage'])){
                $exposureInfo['push_minage_word'] = $exposureInfo['push_minage'];
            }
            $exposureInfo['push_maxage_word'] = '全部';
            if(!empty($exposureInfo['push_maxage'])){
                $exposureInfo['push_maxage_word'] = $exposureInfo['push_maxage'];
            }
            if(empty($exposureInfo['push_code'])){
                $exposureInfo['push_code_word'] = '全部';
            }else{
                $codeInfo = $IndexTableModel->getFind('fa_area',"`adcode` = '{$exposureInfo['push_code']}'",'name');
                $exposureInfo['push_code_word'] = !empty($codeInfo)?$codeInfo['name']:'-';
            }
            if(empty($exposureInfo['push_circle'])){
                $exposureInfo['push_circle_word'] = '全部';
            }else{
                $circleInfo = $IndexTableModel->getFind('fa_circle_list',"`id` = '{$exposureInfo['push_circle']}'",'circle_name');
                $exposureInfo['push_circle_word'] = !empty($circleInfo)?$circleInfo['circle_name']:'-';
            }
            if(!empty($exposureInfo['is_admin_user_id'])){
                $exposureInfo['t_member_id'] = '平台（非前端用户）';
                $exposureInfo['me_uid'] = '平台（非前端用户）';
                $exposureInfo['me_nick_name'] = '平台（非前端用户）';
            }
            $exposureInfo['add_time'] = date('Y-m-d H:i:s',$exposureInfo['add_time']);
        }

        $this->assign([
            'videoInfo' => $videoInfo,
            'data' => $exposureInfo,
            'exposure_id' => $id,
        ]);
        return $this->fetch();
    }

    /**
     * 平台推广短视频
     * User:@hang
     */
    public function pttg($id){
        //操作上锁
        $Redis_Lock = new \Redislock();
        $otc_sell_key = 'lock:pttg';    // 定义锁标识
        $is_lock = $Redis_Lock->lock($otc_sell_key, 15);    // 获取锁
        //解锁失败
        if (!$is_lock) {
            return '操作频繁，请稍后再试！';
        }
        $IndexTableModel = New IndexTableModel();
        if(empty($id)){
            $Redis_Lock->unlock($otc_sell_key);    //释放锁
            return '请选择要推广的短视频作品';
        }
        $tinfo = '';
        $id_str = '';
        foreach ($id as $k=>$v){
            //查询作品是否已经推广
            $exposureInfo = $IndexTableModel->getFindOrder('fa_short_video_exposure_order',"`short_video_id` = '{$v}' and `push_status` < 2",'id,push_status,short_video_id','id desc');
            if(!empty($exposureInfo)){
                $tinfo .= '【视频ID'.$exposureInfo['short_video_id'].'】';
            }
            $id_str .= $v.',';
        }
        if(!empty($tinfo)){
            $Redis_Lock->unlock($otc_sell_key);    //释放锁
            return '抱歉，您选择的短视频中：'.$tinfo.'已经存在未开始或进行中的推广，与后台管理端推广冲突，请不要选择上述短视频作品！';
        }
        $circle_list = $IndexTableModel->getList('fa_circle_list',"`circle_status` = 1",'id,circle_name','id asc');
        $this->assign([
            'id_str' => trim($id_str,','),
            'circle_list' => $circle_list,
        ]);
        $Redis_Lock->unlock($otc_sell_key);    //释放锁
        return $this->fetch();
    }



    /**
     * 执行平台推广短视频
     * User:@hang
     */
    public function actionpttg(){
        $id_str = input('id_str');
        $push_exposure_num = input('push_exposure_num');
        $push_start_time = input('push_start_time');
        $push_end_time = input('push_end_time');
        $push_sex = input('push_sex');
        $push_minage = input('push_minage');
        $push_maxage = input('push_maxage');
        $provinces = input('provinces');
        $citys = input('citys');
        $qus = input('qus');
        $push_circle = input('push_circle');

        $IndexTableModel = New IndexTableModel();
        //操作上锁
        $Redis_Lock = new \Redislock();
        $otc_sell_key = 'lock:actionpttg';    // 定义锁标识
        $is_lock = $Redis_Lock->lock($otc_sell_key, 15);    // 获取锁
        //解锁失败
        if (!$is_lock) {
            return admin_error('操作频繁，请稍后再试！',URL_CLOSE_REFRESH);
        }
        if(empty($id_str)){
            $Redis_Lock->unlock($otc_sell_key);	//释放锁
            return admin_error('请选择要推广的短视频作品',URL_CLOSE_REFRESH);
        }
        if(!is_numeric($push_exposure_num) || getFloatLength($push_exposure_num) > 0 || $push_exposure_num <= 0){
            $Redis_Lock->unlock($otc_sell_key);	//释放锁
            return admin_error('曝光次数填写错误',URL_CLOSE_REFRESH);
        }
        if(empty($push_start_time) || empty($push_end_time)){
            $Redis_Lock->unlock($otc_sell_key);	//释放锁
            return admin_error('请选择推广开始和结束时间错误',URL_CLOSE_REFRESH);
        }
        $push_start_time = strtotime($push_start_time);
        $push_end_time = strtotime($push_end_time);
        if(!is_numeric($push_start_time) || !is_numeric($push_end_time)){
            $Redis_Lock->unlock($otc_sell_key);	//释放锁
            return admin_error('推广时间转换时间戳错误',URL_CLOSE_REFRESH);
        }
        if($push_start_time <= time()){
            $Redis_Lock->unlock($otc_sell_key);	//释放锁
            return admin_error('推广开始时间应大于当前时间',URL_CLOSE_REFRESH);
        }
        if($push_start_time >= $push_end_time){
            $Redis_Lock->unlock($otc_sell_key);	//释放锁
            return admin_error('推广开始时间应小于结束时间',URL_CLOSE_REFRESH);
        }
        if(!in_array($push_sex,[0,1,2])){
            $Redis_Lock->unlock($otc_sell_key);	//释放锁
            return admin_error('推广性别选择错误',URL_CLOSE_REFRESH);
        }
        if(!is_numeric($push_minage) || getFloatLength($push_minage) > 0 || !is_numeric($push_maxage) || getFloatLength($push_maxage) > 0){
            $Redis_Lock->unlock($otc_sell_key);	//释放锁
            return admin_error('推广年龄选择错误',URL_CLOSE_REFRESH);
        }
        if($push_minage > $push_maxage){
            $Redis_Lock->unlock($otc_sell_key);	//释放锁
            return admin_error('推广最小年龄不可大于推广最大年龄',URL_CLOSE_REFRESH);
        }
        $push_code = 0;
        if(!empty($qus)){
            $quInfo = $IndexTableModel->getFind('fa_area',"`level` = 3 and `name` = '{$qus}'",'adcode');
            if(empty($quInfo)){
                $Redis_Lock->unlock($otc_sell_key);	//释放锁
                return admin_error('获取区信息失败',URL_CLOSE_REFRESH);
            }
            $push_code = $quInfo['adcode'];
        }else{
            if(!empty($citys)){
                $citysInfo = $IndexTableModel->getFind('fa_area',"`level` = 2 and `name` = '{$citys}'",'adcode');
                if(empty($citysInfo)){
                    $Redis_Lock->unlock($otc_sell_key);	//释放锁
                    return admin_error('获取市信息失败',URL_CLOSE_REFRESH);
                }
                $push_code = $citysInfo['adcode'];
            }else{
                if(!empty($provinces)){
                    $provincesInfo = $IndexTableModel->getFind('fa_area',"`level` = 1 and `name` = '{$provinces}'",'adcode');
                    if(empty($provincesInfo)){
                        $Redis_Lock->unlock($otc_sell_key);	//释放锁
                        return admin_error('获取省信息失败',URL_CLOSE_REFRESH);
                    }
                    $push_code = $provincesInfo['adcode'];
                }
            }
        }
        if(!is_numeric($push_code)){
            $Redis_Lock->unlock($otc_sell_key);	//释放锁
            return admin_error('推广地区选择错误',URL_CLOSE_REFRESH);
        }
        if(!is_numeric($push_circle)){
            $Redis_Lock->unlock($otc_sell_key);	//释放锁
            return admin_error('推广圈层选择错误',URL_CLOSE_REFRESH);
        }

        $id_arr = explode(',',trim($id_str,','));
        Db::startTrans();
        $ctime = time();
        $admin_user_id = $this->uid;
        foreach ($id_arr as $k=>$v){
            $videoInfo = $IndexTableModel->getFind('fa_short_video',"`id` = '{$v}'",'id,member_id,is_show,short_content,member_id,all_exposure_num,exposure_num');
            if(empty($videoInfo)){
                Db::rollBack();
                $Redis_Lock->unlock($otc_sell_key);	//释放锁
                return admin_error('短视频ID为'.$v.'的作品信息未查询到',URL_CLOSE_REFRESH);
            }
            if($videoInfo['is_show'] != 1){
                Db::rollBack();
                $Redis_Lock->unlock($otc_sell_key);	//释放锁
                return admin_error('短视频ID为'.$v.'的作品已经下架，不可推广',URL_CLOSE_REFRESH);
            }
            //查询作品推广信息
            $videoExposureInfo = $IndexTableModel->getFind('fa_short_video_exposure_order',"`short_video_id` = '{$v}' and `push_status` in(0,1)",'*');
            if(!empty($videoExposureInfo)){
                Db::rollBack();
                $Redis_Lock->unlock($otc_sell_key);	//释放锁
                return admin_error('短视频ID为'.$v.'的作品已经存在推广，请检查',URL_CLOSE_REFRESH);
            }
            //执行后台管理端推广
            //生成推广订单
            $order_info = array();
            $order_info['member_id'] = 1;
            $order_info['push_exposure_num'] = $push_exposure_num;
            $order_info['surplus_exposure_num'] = $push_exposure_num;
            $order_info['short_video_id'] = $v;
            $order_info['short_video_member_id'] = $videoInfo['member_id'];
            $order_info['push_start_time'] = $push_start_time;
            $order_info['push_end_time'] = $push_end_time;
            $order_info['push_sex'] = $push_sex;
            $order_info['push_minage'] = $push_minage;
            $order_info['push_maxage'] = $push_maxage;
            $order_info['push_code'] = $push_code;
            $order_info['push_circle'] = $push_circle;
            $order_info['push_status'] = 0;
            $order_info['add_time'] = $ctime;
            $order_info['is_admin_user_id'] = $admin_user_id;
            $order_res = $IndexTableModel->addInfo('fa_short_video_exposure_order',$order_info);
            if(empty($order_res)){
                Db::rollBack();
                $Redis_Lock->unlock($otc_sell_key);	//释放锁
                return admin_error('短视频ID为'.$v.'的作品生成推广订单失败',URL_CLOSE_REFRESH);
            }
        }
        Db::commit();
        $Redis_Lock->unlock($otc_sell_key);	//释放锁
        return admin_success('后台管理端为作品推广成功',URL_CLOSE_REFRESH);
    }


    /**
     * 批量开启置前
     * User:@hang
     */
    public function plzq($id)
    {
        $result = Db::table('fa_short_video')->whereIn('id', $id)->update(['sort' => -99]);
        return $result ? admin_success('操作成功', URL_RELOAD) : admin_error();
    }


    /**
     * 批量取消置前
     * User:@hang
     */
    public function qxplzq($id)
    {
        $result = Db::table('fa_short_video')->whereIn('id', $id)->update(['sort' => 1]);
        return $result ? admin_success('操作成功', URL_RELOAD) : admin_error();
    }



    /**
     * 封禁作品
     * User:@hang
     */
    public function disable($id){
        //操作上锁
        $Redis_Lock  =  new \Redislock();
        $otc_sell_key  =  'lock:disablevideos';	// 定义锁标识
        $is_lock  =  $Redis_Lock->lock($otc_sell_key, 15);	// 获取锁
        //解锁失败
        if(!$is_lock){
            return admin_error('操作频繁，请稍后再试！',URL_CLOSE_REFRESH);
        }
        $res = Db::table('fa_short_video')->whereIn('id', $id)->update(array('status'=>2,'is_show'=>2));
        if(empty($res)){
            $Redis_Lock->unlock($otc_sell_key);	//释放锁
            return admin_error('封禁作品失败',URL_CLOSE_REFRESH);
        }
        $Redis_Lock->unlock($otc_sell_key);	//释放锁
        return admin_success('封禁作品成功', URL_RELOAD);
    }


    /**
     * 解封作品
     * User:@hang
     */
    public function enable($id){
        //操作上锁
        $Redis_Lock  =  new \Redislock();
        $otc_sell_key  =  'lock:enablevideos';	// 定义锁标识
        $is_lock  =  $Redis_Lock->lock($otc_sell_key, 15);	// 获取锁
        //解锁失败
        if(!$is_lock){
            return admin_error('操作频繁，请稍后再试！',URL_CLOSE_REFRESH);
        }
        $res = Db::table('fa_short_video')->whereIn('id', $id)->update(array('status'=>1,'is_show'=>1));
        if(empty($res)){
            $Redis_Lock->unlock($otc_sell_key);	//释放锁
            return admin_error('解封作品失败',URL_CLOSE_REFRESH);
        }
        $Redis_Lock->unlock($otc_sell_key);	//释放锁
        return admin_success('解封作品成功', URL_RELOAD);
    }


    /**
     * 优质短视频
     * User:@hang
     */
    public function highindex(Request $request)
    {
        $IndexTableModel = New IndexTableModel();
        $param = $request->param();
        $whehe = array();
        $whehe[] = ['a.exposure_num','neq',-1];
        if (isset($param['member_id']) && !empty($param['member_id'])) {
            $whehe[] = ['b.member_id','=',$param['member_id']];
        }
        if (isset($param['me_uid']) && !empty($param['me_uid'])) {
            $whehe[] = ['b.me_uid|b.me_nick_name','like',"%{$param['me_uid']}%"];
        }
        if (isset($param['me_phone']) && !empty($param['me_phone'])) {
            $whehe[] = ['b.me_phone','like',"%{$param['me_phone']}%"];
        }
        if (isset($param['me_nick_name']) && !empty($param['me_nick_name'])) {
            $whehe[] = ['b.me_nick_name','like',"%{$param['me_nick_name']}%"];
        }
        if (isset($param['label_name']) && !empty($param['label_name'])) {
            $whehe[] = ['c.label_name','like',"%{$param['label_name']}%"];
        }
        if (isset($param['short_content']) && !empty($param['short_content'])) {
            $whehe[] = ['a.short_content','like',"%{$param['short_content']}%"];
        }
        if (isset($param['status']) && !empty($param['status'])) {
            $whehe[] = ['a.status','=',$param['status']];
        }
        if (isset($param['is_show']) && !empty($param['is_show'])) {
            $whehe[] = ['a.is_show','=',$param['is_show']];
        }
        if (isset($param['is_delete']) && !empty($param['is_delete'])) {
            $whehe[] = ['a.is_delete','=',$param['is_delete']];
        }
        if (isset($param['is_zx_word']) && !empty($param['is_zx_word'])) {
            if($param['is_zx_word'] == 1){
                $whehe[] = ['a.sort','=',-99];
            }
            if($param['is_zx_word'] == 2){
                $whehe[] = ['a.sort','neq',-99];
            }
        }
        $whehetime = '';
        if (isset($param['add_time']) && !empty($param['add_time'])) {
            $time_arr = explode(' - ', $param['add_time']);
            $start_time = strtotime($time_arr[0]);
            $end_time = strtotime($time_arr[1].'23:59:59');
            $whehetime = "a.add_time >= $start_time AND a.add_time <= $end_time";
        }

        $order = 'a.like_num desc,a.comment_num desc,a.collection_num desc,a.share_num desc,a.add_time desc';
        if (isset($param['px']) && !empty($param['px'])) {
            switch($param['px']){
                case '1': $order = 'a.like_num desc,a.add_time desc';break;
                case '2': $order = 'a.comment_num desc,a.add_time desc';break;
                case '3': $order = 'a.collection_num desc,a.add_time desc';break;
                case '4': $order = 'a.share_num desc,a.add_time desc';break;
            }
        }

        $data = Db::table('fa_short_video')
            ->alias('a')
            ->join("fa_member b",'a.member_id = b.member_id','LEFT')
            ->join("fa_label c",'a.label_id = c.id','LEFT')
            ->join("fa_short_exposure_pool d",'a.pool_id = d.id','LEFT')
            ->where($whehe)
            ->where($whehetime)
            ->field('a.*,b.me_uid,b.me_nick_name,b.me_phone,c.label_name,d.pool_name,d.exposure_num as pool_exposure_num')
            ->order($order)
            ->paginate($this->admin['per_page'],false,['query'=>request()->param()]);
        $data->each(function ($v, $k)use($IndexTableModel) {
            switch($v['status']){
                case '1': $v['status_word'] = '正常';break;
                case '2': $v['status_word'] = '封禁';break;
            }
            switch($v['is_show']){
                case '1': $v['is_show_word'] = '展示';break;
                case '2': $v['is_show_word'] = '隐藏';break;
            }
            switch($v['is_delete']){
                case '1': $v['is_delete_word'] = '未删除';break;
                case '2': $v['is_delete_word'] = '已删除';break;
            }
            $v['add_time'] = date('Y-m-d H:i',$v['add_time']);
            //查询是否存在推广
            $v['is_exposure_word'] = '未推广';
            $v['is_exposure'] = '-1';
            $v['exposure_id'] = '0';
            $exposureInfo = $IndexTableModel->getFindOrder('fa_short_video_exposure_order',"`short_video_id` = '{$v['id']}' and `push_status` < 2",'id,push_status','id desc');
            if(!empty($exposureInfo)){
                $v['is_exposure_word'] = $exposureInfo['push_status'] == 0?'未开始':'推广中';
                $v['is_exposure'] = $exposureInfo['push_status'] == 0?'0':'1';
                $v['exposure_id'] = $exposureInfo['id'];
            }
            $v['short_content_word'] = cutStr($v['short_content'],7);
            $v['is_zx_word'] = '否';
            if($v['sort'] == -99){
                $v['is_zx_word'] = '是';
            }
            return $v;
        });
        //关键词，排序等赋值
        $this->assign($request->get());
        $this->assign([
            'data'  => $data,
            'page'  => $data->render(),
            'total' => $data->total(),
        ]);
        return $this->fetch();
    }









    /**
     * 获取省份
     * @Author: Xu
     *
     */
    public function getProvinceList(){
        $IndexTableModel = New IndexTableModel();
        $list = $IndexTableModel->getList('fa_area',array('level'=>1,'parent_id'=>100000),'adcode,name as province_name','adcode asc');
        return json_encode($list);
    }

    /**
     * 根据省份获取市
     * @Author: Xu
     *
     */
    public function getCityList(){
        $rule_province = input('rule_province');
        //查询选择的省份
        $IndexTableModel = New IndexTableModel();
        $provinceInfo = $IndexTableModel->getFind('fa_area',array('level'=>1,'parent_id'=>100000,'name'=>$rule_province),'adcode');
        $list = array();
        if(!empty($provinceInfo)){
            $list = $IndexTableModel->getList('fa_area',array('parent_id'=>$provinceInfo['adcode'],'level'=>2),'adcode,name as city_name','adcode asc');
        }
        return json_encode($list);
    }

    /**
     * 根据市获取区
     * @Author: Xu
     *
     */
    public function getQuList(){
        $rule_city = input('rule_city');
        //查询选择的市
        $IndexTableModel = New IndexTableModel();
        $cityInfo = $IndexTableModel->getFind('fa_area',array('level'=>2,'name'=>$rule_city),'adcode');
        $list = array();
        if(!empty($cityInfo)){
            $list = $IndexTableModel->getList('fa_area',array('parent_id'=>$cityInfo['adcode'],'level'=>3),'adcode,name as city_name','adcode asc');
        }
        return json_encode($list);
    }

}
